/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ClientGUI.java
 *
 * Created on Nov 15, 2011, 3:33:51 AM
 */
package marketplace_client;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import marketplace_server.Item;
import marketplace_server.RejectedException;

/**
 *
 * @author gianmariospacagna
 */
public class ClientGUI extends javax.swing.JFrame {
    private ClientImpl myClient;

   
    /** Creates new form ClientGUI */
    public ClientGUI(ClientImpl myClient) {
        initComponents();
        this.myClient=myClient;
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToggleButton1 = new javax.swing.JToggleButton();
        jLabel1 = new javax.swing.JLabel();
        jButtonBuy = new javax.swing.JButton();
        jTextFieldDesiredPrice = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButtonWish = new javax.swing.JButton();
        jTextFieldName = new javax.swing.JTextField();
        jTextFieldPrice = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButtonSell = new javax.swing.JButton();
        jButtonUpdate = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButtonRegister = new javax.swing.JButton();
        jButtonUnregister = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableItemContainer = new javax.swing.JTable();
        jButtonCreateAccount = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTextFieldFundsInput = new javax.swing.JTextField();
        jLabelCurrentBalance = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextAreaNotifications = new javax.swing.JTextArea();
        jTextFieldUsername = new javax.swing.JTextField();
        jTextFieldPassword = new javax.swing.JTextField();
        jButtonLogIn = new javax.swing.JButton();

        jToggleButton1.setText("jToggleButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Items available on the market:");

        jButtonBuy.setText("Buy");
        jButtonBuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuyActionPerformed(evt);
            }
        });

        jTextFieldDesiredPrice.setText("0");

        jLabel2.setText("Maximum price:");

        jButtonWish.setText("Submit price range");
        jButtonWish.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                requestPriceRange(evt);
            }
        });

        jTextFieldName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNameActionPerformed(evt);
            }
        });

        jLabel3.setText("Name:");

        jLabel4.setText("Price:");

        jButtonSell.setText("Sell");
        jButtonSell.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSellActionPerformed(evt);
            }
        });

        jButtonUpdate.setText("Update");
        jButtonUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUpdateActionPerformed(evt);
            }
        });

        jButton1.setText("Refresh List");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButtonRegister.setText("Register");
        jButtonRegister.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegisterActionPerformed(evt);
            }
        });

        jButtonUnregister.setText("Unregister");
        jButtonUnregister.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUnregisterActionPerformed(evt);
            }
        });

        jTableItemContainer.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Owner", "Name", "Price", "Seller"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTableItemContainer);

        jButtonCreateAccount.setText("Create Bank Account");
        jButtonCreateAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createBankAccount(evt);
            }
        });

        jButton2.setText("Deposit funds");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                depositFunds(evt);
            }
        });

        jLabelCurrentBalance.setText("$0");

        jLabel6.setText("Balance :");

        jLabel5.setText("Notifications :");

        jTextAreaNotifications.setColumns(20);
        jTextAreaNotifications.setRows(5);
        jScrollPane3.setViewportView(jTextAreaNotifications);

        jTextFieldUsername.setText("username");

        jTextFieldPassword.setText("password");

        jButtonLogIn.setText("Log in");
        jButtonLogIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLogInActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jTextFieldPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jTextFieldUsername, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jButtonUnregister)
                                .add(jButtonLogIn)
                                .add(jButtonRegister)))
                        .add(101, 101, 101)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel2)
                                .add(18, 18, 18)
                                .add(jTextFieldDesiredPrice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(1, 1, 1)
                                .add(jButtonWish))
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jLabel3)
                                    .add(jLabel4))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(jTextFieldPrice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 114, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jButtonSell))
                                    .add(jTextFieldName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 191, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jButtonCreateAccount))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jTextFieldFundsInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 163, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton2)
                        .add(18, 18, 18)
                        .add(jLabel6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabelCurrentBalance)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 151, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(28, 28, 28)
                                .add(jLabel1)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 60, Short.MAX_VALUE)
                                .add(jButton1)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jButtonBuy)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButtonUpdate))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .addContainerGap()
                                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)))
                        .add(43, 43, 43)))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel5)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE))
                .add(43, 43, 43))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldDesiredPrice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2)
                    .add(jButtonWish)
                    .add(jTextFieldUsername, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jTextFieldName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel3))
                        .add(2, 2, 2))
                    .add(layout.createSequentialGroup()
                        .add(jTextFieldPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonLogIn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldPrice, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButtonSell)
                    .add(jLabel4)
                    .add(jButtonUnregister))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonRegister)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jButtonUpdate)
                    .add(jButtonBuy)
                    .add(jButton1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 117, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jButtonCreateAccount)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldFundsInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton2)
                    .add(jLabelCurrentBalance)
                    .add(jLabel6))
                .add(1, 1, 1)
                .add(jLabel5)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(170, 170, 170))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    
    private void jTextFieldNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNameActionPerformed

    private void jButtonSellActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSellActionPerformed
        if (myClient.hasBankAccount()){
            try {
                String name=jTextFieldName.getText();
                int price=Integer.parseInt(jTextFieldPrice.getText());

                
                myClient.publishItemToServer(name, price);
                //myClient.listItemsOnServer();
            } catch (RemoteException ex) {
                Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        else {
            JOptionPane.showConfirmDialog(rootPane, "Create a bank account first!");
        }
        
    }//GEN-LAST:event_jButtonSellActionPerformed

    private void jButtonBuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuyActionPerformed
        if (myClient.hasBankAccount()) {
            int row=jTableItemContainer.getSelectedRow();
        
            Object nameObject   =   jTableItemContainer.getValueAt(row, 1);
            Object priceObject  =   jTableItemContainer.getValueAt(row, 2);
            Object sellerObject =   jTableItemContainer.getValueAt(row, 3);

            // Quick ugly hack to fix the exception being thrown when casting 'getValue' to Integer or String

            String name     = nameObject.toString();
            Integer price   = Integer.parseInt(priceObject.toString());
            String sellerId = sellerObject.toString();

            if (sellerId.equalsIgnoreCase(myClient.getID())) {
                JOptionPane.showMessageDialog(rootPane, "You can't buy something you already own, silly!");
            }
            else {
                try {
                    try {
                        
                        
                        myClient.buyItem(name);
                        // The list gets updated server side
                    } catch (RejectedException ex) {
                        Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (RemoteException ex) {
                    Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        else {
            JOptionPane.showConfirmDialog(rootPane, "Create a bank account first!");
        }
    }//GEN-LAST:event_jButtonBuyActionPerformed

    private void jButtonUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpdateActionPerformed
        
        if (myClient.hasBankAccount()) {
            
            int row=jTableItemContainer.getSelectedRow();
        
            Object nameObject   = jTableItemContainer.getValueAt(row, 1);
            Object sellerObject = jTableItemContainer.getValueAt(row, 3);

            // Quick ugly hack to fix the exception being thrown when casting 'getValue' to Integer or String

            String name     = nameObject.toString();
            String seller   = sellerObject.toString();
            
            if (myClient.getID().equalsIgnoreCase(seller)) {
                String newPrice = JOptionPane.showInputDialog(rootPane, "Insert new price");
                try {
                    myClient.updatePriceOfItemWitName(name, Integer.parseInt(newPrice));
                    myClient.listItemsOnServer();
                } catch (RemoteException ex) {
                    Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            else {
                JOptionPane.showConfirmDialog(rootPane, "You can't change the price of somebody elses item, silly!");
            }
        }
        else {
            JOptionPane.showConfirmDialog(rootPane, "Create a bank account first!");
        }
        
    }//GEN-LAST:event_jButtonUpdateActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    if (myClient.hasBankAccount()) {
        try {myClient.listItemsOnServer();}catch(Exception e) { e.printStackTrace();}
    }
    else {
        JOptionPane.showConfirmDialog(rootPane, "Create a bank account first!");

    }
    
    
}//GEN-LAST:event_jButton1ActionPerformed

private void jButtonRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegisterActionPerformed
    if (myClient.hasBankAccount()) {
        try {
            
            String username = this.jTextFieldUsername.getText();
            String password =this.jTextFieldPassword.getText();
            
            myClient.register(username,password);
        } catch (RemoteException ex) {
            Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    else {
        JOptionPane.showConfirmDialog(rootPane, "Create a bank account first!");

    }    
    
}//GEN-LAST:event_jButtonRegisterActionPerformed

private void jButtonUnregisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUnregisterActionPerformed
    if (myClient.hasBankAccount()) {
        try {
            myClient.unregister();
        } catch (RemoteException ex) {
            Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    else {
        JOptionPane.showConfirmDialog(rootPane, "Create a bank account first!");

    }   
    
}//GEN-LAST:event_jButtonUnregisterActionPerformed

private void requestPriceRange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_requestPriceRange
        if (myClient.hasBankAccount()) {
            try {
                myClient.requestPriceRange(Integer.parseInt(jTextFieldDesiredPrice.getText()));
            } catch (RemoteException ex) {
                Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }    
        else {
                JOptionPane.showConfirmDialog(rootPane, "Create a bank account first!");
        }    
    
}//GEN-LAST:event_requestPriceRange

private void createBankAccount(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createBankAccount
    try {
         myClient.createBankAccount();
    } catch (Exception e) {
        e.printStackTrace();
    }
   
}//GEN-LAST:event_createBankAccount

private void depositFunds(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_depositFunds
    try {
        myClient.deposit(Integer.parseInt(jTextFieldFundsInput.getText()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    
}//GEN-LAST:event_depositFunds

    private void jButtonLogInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLogInActionPerformed
    if (myClient.hasBankAccount() && myClient.isRegistered()) {
        String usr = jTextFieldUsername.getText();
           String pwd = jTextFieldPassword.getText();
            try {
                myClient.login (usr,pwd);
            } catch (RemoteException ex) {
                Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
    else
        JOPtion
        
    }//GEN-LAST:event_jButtonLogInActionPerformed
public void refreshTableWithItems (ArrayList<Item> items) throws RemoteException {
    DefaultTableModel model = new DefaultTableModel();
            
    model.addColumn("Owner");
    model.addColumn("Name");
    model.addColumn("Price");
    model.addColumn("Seller");
    
    for (Item i : items) {
       // The owner of the item depends on if it's for sale/has been bought or not
       String ownerString = i.getBuyer() == null ? i.getSeller() : i.getBuyer();
       
       System.out.println(i.getName()+" has a buyer : "+i.getBuyer());
       System.out.println("owner of "+i.getName()+" is "+ownerString);
        
        model.addRow(new Object[]{ownerString,i.getName(),i.getPrice(),i.getSeller()});
    }
    
    jTableItemContainer.setModel(model);    
    jTableItemContainer.revalidate();
    jTableItemContainer.updateUI();

 }
public void updateBalance () throws RemoteException, RejectedException {
    jLabelCurrentBalance.setText(""+myClient.getBalance());
}
public void notifyUserOfItemStatus (Item item) {
    
    try {
        String msg = "Your "+item.getName()+" just got sold to "+item.getBuyer();
        jTextAreaNotifications.setText(jTextAreaNotifications.getText()+msg+"\n");
    } catch (Exception ex) {
        Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}
public void notifyUserOfItemInPriceRange (ArrayList<Item> items) {
    for (Item item : items) {
        jTextAreaNotifications.setText(jTextAreaNotifications.getText()+"Item: "+item.getName()+" is within your price range"+"\n");
    }
}
public void notifyUserOfTransactionStatus (String exceptionMessage) {
    jTextAreaNotifications.setText(jTextAreaNotifications.getText()+exceptionMessage+"\n");
}
    /**
     * @param args the command line arguments
     */
    public static void startGUI(final ClientImpl myClient) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ClientGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ClientGUI(myClient).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButtonBuy;
    private javax.swing.JButton jButtonCreateAccount;
    private javax.swing.JButton jButtonLogIn;
    private javax.swing.JButton jButtonRegister;
    private javax.swing.JButton jButtonSell;
    private javax.swing.JButton jButtonUnregister;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JButton jButtonWish;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabelCurrentBalance;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTableItemContainer;
    private javax.swing.JTextArea jTextAreaNotifications;
    private javax.swing.JTextField jTextFieldDesiredPrice;
    private javax.swing.JTextField jTextFieldFundsInput;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldPassword;
    private javax.swing.JTextField jTextFieldPrice;
    private javax.swing.JTextField jTextFieldUsername;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables
}
